package com.wushuu.ce.ui.activity;


import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.wushuu.ce.R;

import org.xutils.view.annotation.ContentView;

/**
 * Created by wushuu on 2016/5/11.
 */
@ContentView(R.layout.activity_practice_level)
public class PracticeLevelActivity extends BaseActivity {

    private LinearLayout btnContainer;
    private final int CHARPTER_NUM = 40;



    @Override
    public void init() {
        btnContainer = (LinearLayout) findViewById(R.id.btn_container);
        for(int i = 1; i <= CHARPTER_NUM; i++){
            Button btn = new Button(getApplicationContext());
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100,100);
            btn.setText(String.valueOf(i));
            params.bottomMargin = 5;
            btn.setLayoutParams(params);
            btnContainer.addView(btn);
        }
        setOnClickListener();
    }


    private void setOnClickListener() {
        for(int i = 0; i < CHARPTER_NUM; i++){
            final int finalI = i+1;
            btnContainer.getChildAt(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(PracticeLevelActivity.this,ChapterPracticeActivity.class);
                    intent.putExtra("charpterName", String.valueOf(finalI));
                    startActivity(intent);
                }
            });
        }
    }
}
